package com.ttg.utils.sm2;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class SecureRandomUtil {
    public static SecureRandom getSecureRandomInstance()  {
        SecureRandom mSecureRandom = null;
        if(isLinux()) {
            //非阻塞模式+伪随机
            try {
                System.out.println("secureRandom非阻塞模式初始化");
                mSecureRandom = SecureRandom.getInstance("NativePRNGNonBlocking");
            } catch (NoSuchAlgorithmException e) {
                mSecureRandom = new SecureRandom();
            }
        }else{
            mSecureRandom = new SecureRandom();
        }
        return mSecureRandom;
    }

    public static boolean isLinux() {
        return System.getProperty("os.name").toLowerCase().contains("linux");
    }

}
